﻿using System;
using System.Collections.Generic;
using System.Linq;
using Devbridge.IPolice.DataContracts;
using Devbridge.IPolice.DomainModel;
using Devbridge.IPolice.Repositories;
using Devbridge.IPolice.ServiceContracts;

namespace Devbridge.IPolice.Services
{
    public class OffenderService : IOffenderService
    {
        private readonly IOffenderRepository offenderRepository;
        
        public OffenderService()
        {
            offenderRepository = new OffenderRepository();
        }

        public IList<Offender> GetByFirstName(string firstName)
        {
            return offenderRepository.AllQuery()
                .Where(f => f.FirstName.ToLower().Contains(firstName.ToLower()))
                .ToList();
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            offenderRepository.Dispose();
        }
    }
}